<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="1200">
    <ContentWrap>
      <el-table :header-cell-style="{ background: '#f0f0f0' }" border v-loading="loading" :data="list" :stripe="true">
        <el-table-column label="企微员工ID" align="left" prop="weUserId" />
        <el-table-column label="客户姓名" align="left" prop="weCustomerName" />
        <el-table-column label="企微员工姓名" align="left" prop="weUserName" />
        <el-table-column label="会话状态" align="left" prop="chatStatus">
          <template #default="scope">
            {{ StatusMap[scope.row.chatStatus] }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" :formatter="dateFormatter" />
      </el-table>
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>
<script setup lang="ts">
import * as AcqLinkApi from '@/api/wecom/acqlink'
import { dateFormatter } from '@/utils/formatTime'

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('客户列表') // 弹窗的标题
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  weLinkId: undefined
})

const StatusMap = {
  0: '客户未发消息',
  1: '客户已发送消息',
  2: '客户发送消息状态未知',
}

/** 打开弹窗 */
const open = async (id?: number) => {
  dialogVisible.value = true
  queryParams.weLinkId = id
  await getList()
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await AcqLinkApi.getAcqCustomerPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
</script>
